<template>
  <div class="user-contalner">
    <!-- 顶部栏 -->
    <div class="header">
      <van-image
        width="60"
        height="60"
        round
        fit="cover"
        :src="userInfo.photo"
      />
      <h4>
        {{ userInfo.name }}
        <br />
        <van-tag color="#fff" text-color="#0098fa">{{
          userInfo.birthday
        }}</van-tag>
      </h4>
    </div>
    <!-- 用户导航栏 -->
    <van-row>
      <van-col span="8">
        <van-icon name="newspaper-o" color="#8cc3ff" />
        <span>我的作品</span>
      </van-col>
      <van-col span="8">
        <van-icon name="star-o" color="#ff576a" />
        <span>我的收藏</span>
      </van-col>
      <van-col span="8">
        <van-icon name="tosend" color="#ffb731" />
        <span>阅读历史</span>
      </van-col>
    </van-row>
    <!-- cell列表 -->
    <van-cell title="编辑资料" icon="edit" is-link @click="$router.push('/edit')"/>
    <van-cell title="小智同学" icon="smile-o" is-link />
    <van-cell title="系统设置" icon="setting-o" is-link />
    <van-cell title="退出登录" icon="warning-o" is-link @click="logout" />
  </div>
</template>

<script>
// 引入用户信息接口
import { getUserInfo } from "./user.js";

// 引入token
import {delToken} from '@/utils/token.js'

export default {
  name: "user",
  data() {
    return {
      userInfo: {},
    };
  },
  created() {
    getUserInfo().then((res) => {
      this.userInfo = res.data.data;
      this.$store.state.userInfo = res.data.data;
    });
  },
  methods: {
    logout() {
      // 弹出警示框
      this.$dialog.confirm({
        title: "提示",
        message: "您确定退出吗？",
      })
        .then(() => {
          // 清除token
          delToken();
          // 转到登录页
          this.$router.push('/login')
        })
        .catch(() => {
          return
        });
    },
  },
};
</script>

<style lang="less">
.user-contalner {
  .header {
    display: flex;
    height: 100px;
    background-color: #0098fa;
    align-items: center;
    .van-image {
      margin: 0 15px;
    }
    h4 {
      color: #fff;
      font-size: 16px;
      font-weight: normal;
    }
  }
  .van-col {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin: 10px 0;
    span {
      font-size: 14px;
      margin-top: 5px;
    }
  }
}
</style>